From 64c9fa4bd2ffb9bfb68c3cc6178faf138660ae06 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Mon, 26 Sep 2005 21:49:19 +0000 Subject: [PATCH] reorganizing babl-stats --- babl/Makefile.am | 1 + babl/babl-fish-stats.c | 308 +++++++++++++++++++++++++++++++++++ babl/babl.c | 12 ++ tests/babl_fish_path_dhtml.c | 284 +------------------------------- 4 files changed, 322 insertions(+), 283 deletions(-) create mode 100644 babl/babl-fish-stats.c diff --git a/babl/Makefile.am b/babl/Makefile.am index bcc92a4..dccccab 100644 --- a/babl/Makefile.am +++ b/babl/Makefile.am @@ -16,6 +16,7 @@ c_sources = \ babl-extension.c \ babl-fish.c \ babl-fish-simple.c \ + babl-fish-stats.c \ babl-fish-reference.c \ babl-fish-path.c \ babl-format.c \ diff --git a/babl/babl-fish-stats.c b/babl/babl-fish-stats.c new file mode 100644 index 0000000..b34b03c --- /dev/null +++ b/babl/babl-fish-stats.c @@ -0,0 +1,308 @@ +/* babl - dynamically extendable universal pixel fish library. + * Copyright (C) 2005, Øyvind KolÃ¥s. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General + * Public License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "babl-internal.h" + +static FILE *output_file = NULL; +static int qux=0; + +static char *utf8_bar[]={" ","·","▁","▂","▃","▄","▅","▆","▇","█"}; +//static char *utf8_bar[]= {"!","▁","▃","▅","▇","█","!","!","!"}; +//static char *utf8_bar[]={"·", "█", "▇", "▆", "▅", "▄", "▃", "▂", "▁", }; +//static char *utf8_bar[]={" ","1","2","3","4","5","6","7","8"}; + +static int +table_destination_each (Babl *babl, + void *userdata) +{ + Babl *source = userdata; + Babl *destination = babl; + + if ((qux++) % babl_formats_count () == qux/ babl_formats_count ()) + fprintf (output_file, " "); + else + { + Babl *fish = babl_fish (source, destination); + + babl_assert (fish); + + + switch (fish->class_type) + { + case BABL_FISH_PATH: + + fprintf (output_file, "%s", + fish->fish.processings > 0 ? " style='background-color: #69f'":"", + utf8_bar[fish->fish_path.conversions]); + + { + int i; + fprintf (output_file, "
"); + fprintf (output_file, "

path %s to %s

", source->instance.name, destination->instance.name); + if (fish->fish.processings > 0) + { + fprintf (output_file, "Processings:%i
", fish->fish.processings); + fprintf (output_file, "Pixels:%li
", fish->fish.pixels); + } + fprintf (output_file, "\n"); + + fprintf (output_file, ""); + fprintf (output_file, ""); + fprintf (output_file, ""); + fprintf (output_file, ""); + fprintf (output_file, ""); + + for (i=0; i< fish->fish_path.conversions; i++) + { + fprintf (output_file, ""); + fprintf (output_file, "", BABL(fish->fish_path.conversion[i])->instance.name); + fprintf (output_file, "", babl_conversion_cost (&BABL(fish->fish_path.conversion[i])->conversion)); + fprintf (output_file, "", babl_conversion_error (&BABL(fish->fish_path.conversion[i])->conversion)); + fprintf (output_file, ""); + } + + fprintf (output_file, ""); + fprintf (output_file, ""); + fprintf (output_file, "", fish->fish_path.cost); + fprintf (output_file, "", fish->fish.error); + fprintf (output_file, ""); + fprintf (output_file, "
conversioncosterror
%s%li%e
total%3.0f%e
"); + fprintf (output_file, "
"); + } + fprintf (output_file, "
\n"); + break; + case BABL_FISH_REFERENCE: + fprintf (output_file, " ", + fish->fish.processings > 0 ? " style='background-color: #69f'":""); + fprintf (output_file, "
"); + fprintf (output_file, "

Reference %s to %s

", source->instance.name, destination->instance.name); + + if (fish->fish.processings > 0) + { + fprintf (output_file, "Processings:%i
", fish->fish.processings); + fprintf (output_file, "Pixels:%li
", fish->fish.pixels); + } + fprintf (output_file, "
"); + fprintf (output_file, "
\n"); + break; + default: + babl_assert (0); + break; + } + } + return 0; +} + +static int source_no=0; + +static int +table_source_each (Babl *babl, + void *userdata) +{ + char expanded_name[512]; + const char *s; + char *d; + + s=babl->instance.name; + d=&expanded_name[0]; + + while (*s) + { + switch (*s) + { + case ' ': + *(d++)='&'; + *(d++)='n'; + *(d++)='b'; + *(d++)='s'; + *(d++)='p'; + *(d++)=';'; + *(d) ='\0'; + s++; + break; + default: + *(d++)=*(s++); + *(d) ='\0'; + break; + } + } + + fprintf (output_file, ""); + fprintf (output_file, "%s", expanded_name); + { + int i; + + fprintf (output_file, "
", babl); + fprintf (output_file, "

%s

", babl->instance.name); + + fprintf (output_file, "
"); + fprintf (output_file, "
bytes/pixel
%i
", babl->format.bytes_per_pixel); + fprintf (output_file, "
model
%s
", BABL(babl->format.model)->instance.name ); + fprintf (output_file, "
loss
%f
", babl_format_loss (babl)); + fprintf (output_file, "
components
"); + + for (i=0; i< babl->format.components; i++) + { + fprintf (output_file, "", + BABL(babl->format.type[i])->instance.name, + BABL(babl->format.component[i])->instance.name ); + } + fprintf (output_file, "
%s%s
"); + + fprintf (output_file, "
\n"); + } + + fprintf (output_file, "
"); + babl_format_each (table_destination_each, babl); + fprintf (output_file, "\n"); + source_no++; + return 0; +} + +void +babl_fish_stats (FILE *file) +{ + output_file = file; + + fprintf (output_file, +"\n" +"\n" +"\n" +"\n" +"BablFishPath introspection\n" + + "" + +"" + + +"\n"); + + fprintf (output_file, "\n"); + + fprintf (output_file, "

BablFishPath introspection

"); + fprintf (output_file, "

Instrumentation and pathlengths.

"); + + fprintf (output_file, "\n"); + + babl_format_each (table_source_each, NULL); + + fprintf (output_file, "
Source formatDestination formats
"); + + fprintf (output_file, "
\n"); + + fprintf (output_file, "\n"); +} + diff --git a/babl/babl.c b/babl/babl.c index 438a054..95619f0 100644 --- a/babl/babl.c +++ b/babl/babl.c @@ -52,6 +52,18 @@ babl_destroy (void) { if (!--ref_count) { + if (getenv ("BABL_STATS")) + { + char logfile_name[]="/tmp/babl-stats.html"; + FILE *logfile; + logfile = fopen (logfile_name, "w"); + if (logfile) + { + babl_fish_stats (logfile); + fclose (logfile); + } + } + babl_extension_destroy (); babl_fish_destroy (); babl_conversion_destroy (); diff --git a/tests/babl_fish_path_dhtml.c b/tests/babl_fish_path_dhtml.c index ddd384f..9405fc8 100644 --- a/tests/babl_fish_path_dhtml.c +++ b/tests/babl_fish_path_dhtml.c @@ -1,294 +1,12 @@ -/* perform a symmetricality of conversion test on a set of randomized - * RGBA data */ - #include -#include #include "babl-internal.h" -#define pixels 1024 -int total_length=0; -int total_cost=0; -int total = 0; -int ok = 0; - -static double test[pixels * 4]; - -static void -test_init (void) -{ - int i; - - for (i = 0; i < pixels * 4; i++) - test [i] = (double)random () / RAND_MAX; -} - -static int qux=0; - -static char *utf8_bar[]={" ","·","▁","▂","▃","▄","▅","▆","▇","█"}; -//static char *utf8_bar[]= {"!","▁","▃","▅","▇","█","!","!","!"}; -//static char *utf8_bar[]={"·", "█", "▇", "▆", "▅", "▄", "▃", "▂", "▁", }; -//static char *utf8_bar[]={" ","1","2","3","4","5","6","7","8"}; - -static int -table_destination_each (Babl *babl, - void *userdata) -{ - Babl *source = userdata; - Babl *destination = babl; - - if ((qux++) % babl_formats_count () == qux/ babl_formats_count ()) - printf (" "); - else - { - Babl *temp = babl_fish_path (source, destination); - - if (temp) - { - printf ("%s", - utf8_bar[temp->fish_path.conversions]); - total_length += temp->fish_path.conversions; - total_cost += temp->fish_path.cost; - - { - int i; - printf ("
"); - printf ("

path %s to %s

", source->instance.name, destination->instance.name); - printf ("\n"); - - printf (""); - printf (""); - printf (""); - printf (""); - - for (i=0; i< temp->fish_path.conversions; i++) - { - printf (""); - printf ("", BABL(temp->fish_path.conversion[i])->instance.name); - printf ("", BABL(temp->fish_path.conversion[i])->conversion.cost); - printf (""); - } - - printf (""); - printf (""); - printf ("", temp->fish_path.cost); - printf (""); - printf ("
conversioncost
%s%i
total%3.0f
\n"); - printf ("
\n"); - } - printf ("
"); - ok ++; - total ++; - } - else - { - printf ("%s", " "); - { - printf ("
"); - printf ("

Reference %s to %s

", source->instance.name, destination->instance.name); - printf ("
\n"); - } - printf ("
"); - } - } - return 0; -} - -static int source_no=0; - -static int -table_source_each (Babl *babl, - void *userdata) -{ - char expanded_name[512]; - const char *s; - char *d; - - s=babl->instance.name; - d=&expanded_name[0]; - - while (*s) - { - switch (*s) - { - case ' ': - *(d++)='&'; - *(d++)='n'; - *(d++)='b'; - *(d++)='s'; - *(d++)='p'; - *(d++)=';'; - *(d) ='\0'; - s++; - break; - default: - *(d++)=*(s++); - *(d) ='\0'; - break; - } - } - - printf (""); - printf ("%s", expanded_name); - { - int i; - - printf ("
", babl); - printf ("

%s

", babl->instance.name); - - printf ("
"); - printf ("
bytes/pixel
%i
", babl->format.bytes_per_pixel); - printf ("
model
%s
", BABL(babl->format.model)->instance.name ); - printf ("
loss
%f
", babl->format.loss ); - printf ("
components
"); - - for (i=0; i< babl->format.components; i++) - { - printf ("", - BABL(babl->format.type[i])->instance.name, - BABL(babl->format.component[i])->instance.name ); - } - printf ("
%s%s
"); - - printf ("
\n"); - } - - printf ("
"); - babl_format_each (table_destination_each, babl); - printf ("\n"); - source_no++; - return 0; -} - int main (void) { babl_init (); - test_init (); babl_set_extender (babl_extension_quiet_log ()); - - printf ( -"\n" -"\n" -"\n" -"\n" -"BablFishPath introspection\n" - - "" - -"" - - -"\n"); - - printf ( "\n"); - - printf ("

BablFishPath introspection

"); - printf ("

The table below represents many of the possible conversions available through babl, (the selection of formats includes all formats that shortcut conversions have been registered for.)

"); - printf ("

Hover your mouse over a formats name, or a non blank cell on the horizontal line to see further information, both rows and colums represent pixel formats, but only the vertical axis has labels.

"); - - printf ( "\n"); - babl_format_each (table_source_each, NULL); - printf ("
"); - - printf ("
\n"); - - printf ("\n"); + babl_fish_stats (stdout); babl_destroy (); -- 2.30.2